﻿using Bandit.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BeanGo.DataGridDemo.Models
{
    public class Setting : Bandit.UI.MVVM.NotifyObject
    {
        public static string SavePath { get { return "".GetBaseDirectory() + "Setting.xml"; } }

        /** Software Setting **/

        #region Languages
        /// <summary>
        /// Languages
        /// </summary>
        [System.Xml.Serialization.XmlIgnore]
        public Dictionary<string, string> Languages { get; set; }

        private string _Language;
        /// <summary>
        /// Selected Language
        /// </summary>
        public string Language
        {
            get { return _Language; }
            set
            {
                _Language = value;

                OnPropertyChanged("Language");

                App.ChangeLanguage(value);

                LoadThemes();
            }
        }
        #endregion

        #region Themes
        /// <summary>
        /// Languages
        /// </summary>
        [System.Xml.Serialization.XmlIgnore]
        public Dictionary<string, string> Themes { get; set; }

        private string _Theme;
        /// <summary>
        /// Selected Language
        /// </summary>
        public string Theme
        {
            get { return _Theme; }
            set
            {
                if (value != null)
                {
                    _Theme = value;

                    OnPropertyChanged("Theme");

                    App.ChangeTheme(value);
                }
            }
        }
        #endregion

        #region TestingHide
        private bool _TestingHide;
        /// <summary>
        /// 測試時是否隱藏
        /// </summary>
        public bool TestingHide
        {
            get { return _TestingHide; }
            set
            {
                _TestingHide = value;
                OnPropertyChanged("TestingHide");
            }
        }
        #endregion

        public Setting()
        {
            this.Languages = new Dictionary<string, string>();
            if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Language\Language.xml"))
            {
                System.Xml.Linq.XDocument doc = System.Xml.Linq.XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + @"Language\Language.xml");

                foreach (var item in doc.Root.Elements())
                {
                    if (item.Attribute("Key") != null && item.Attribute("Value") != null)
                    {
                        this.Languages.Add(item.Attribute("Key").Value, item.Attribute("Value").Value);
                    }
                }
            }
        }

        public void LoadThemes()
        {
            this.Themes = new Dictionary<string, string>();
            if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Theme\Theme.xml"))
            {
                System.Xml.Linq.XDocument doc = System.Xml.Linq.XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + @"Theme\Theme.xml");

                foreach (var item in doc.Root.Elements())
                {
                    if (item.Attribute("Key") != null)
                    {
                        this.Themes.Add(item.Attribute("Key").Value, App.GetString(item.Attribute("Key").Value));
                    }
                }
            }

            OnPropertyChanged("Themes");
            this.Theme = this.Theme;

            //var dict = new Dictionary<string, string>();
            //dict.Add("Light", App.GetString("Light"));
            //dict.Add("Dark", App.GetString("Dark"));

            //this.Themes = dict;

            //OnPropertyChanged("Themes");

            //this.Theme = this.Theme;
        }
    }
}
